﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BloodBarEffect : MonoBehaviour {
	[SerializeField] Image mask;
	[SerializeField] Image unMask;
	[SerializeField] float StayTime = 1;
	[SerializeField] float DropSpeed = 0.01f;
	[SerializeField] Animator _animator;
	Timer _timer;

	public void Init(float before, float after) {
		if (_timer == null) { _timer = new(); }
		mask.fillAmount = before;
		unMask.fillAmount = after;
		_animator.Play("HPBarEffect", 0, 0);
		StartCoroutine(Move());
	}

	IEnumerator Move() {
		_timer.Reset();
		float curSpeed = 0.0f;
		while (_timer.Elapsed < StayTime) {
			curSpeed = Mathf.Lerp(curSpeed, DropSpeed, 0.3f);
			transform.position += Vector3.down * curSpeed;
			//Debug.Log("Down");
			yield return null;
		}
		ObjectPool.Instance.RecycleObject(ObjPoolStr.BloodEffect, this.gameObject);
	}
}
